/*
 * Copyright (c) 2024 endless-sky
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef EL_NETWORK_NTP_MANAGER_H
#define EL_NETWORK_NTP_MANAGER_H

#include <string>
#include <vector>
#include <mutex>
#include <nlohmann/json.hpp>
#include "utils_noncopyable.h"

namespace El {
namespace Network {

class NtpManager : public NoCopyable {
public:
    static NtpManager& GetInstance();
    
    // 启动NTP服务并注册配置变更监听
    bool Start();
    
    // 停止NTP服务
    void Stop();
    
    // 配置变更处理
    void HandleNtpConfigChange(const nlohmann::json& config);

private:
    NtpManager() = default;
    ~NtpManager() = default;
    
    // 启动ntpd进程
    bool StartNtpd(const std::vector<std::string>& servers);
    
    // 停止ntpd进程
    bool StopNtpd();
    
    mutable std::mutex mutex_;
    int32_t ntpConfigHandle_;
    bool initialized_;
};

} // namespace Network
} // namespace El

#endif // EL_NETWORK_NTP_MANAGER_H